package top.jolyoulu.core.framework.common

import org.apache.spark.{SparkConf, SparkContext}
import top.jolyoulu.core.framework.controller.WordCountController
import top.jolyoulu.core.framework.util.EnvUtil

/**
 * @Author: JolyouLu
 * @Date: 2024/5/15 18:11
 * @Description
 */
trait TApplication {
  def start(master: String = "local[*]", app: String = "Application")(op: => Unit) = {
    val sparkConf = new SparkConf()
      .setMaster(master)
      .setAppName(app)
    val sc = new SparkContext(sparkConf)
    EnvUtil.put(sc)
    try {
      op
    } catch {
      case ex => println(ex.getMessage)
    }
    sc.stop()
    EnvUtil.clear()
  }
}
